﻿
//修改图书信息
void ModifyBook()
{
	int BookID, BookRecord;
	int FlagExist;//图书编号存在标记
	int item, Num;

	system("cls");
	BookID = SearchBook();
	cout << endl;
	//文件打开失败
	if (BookID == -1)
	{
		return;
	}
	if (BookID == -3)
	{
		return;
	}
	//找到该序号的图书，可以进行修改操作
	BookRecord = ReadBookFile("rb");

	//显示修改选项的子菜单
	cout << endl << "\t1.编号  " << "2.书名  " << "3.作者  " << "4.出版社  " << "5.图书库存量" << endl << endl;
	cout << "\t请输入需要修改的相应信息(输入相应数字)：";
	cin >> item;
	if (item > 5 || item < 1)
	{
		cout << endl << "\t输入数字有误，请退出重新输入";
		return;
	}

	switch (item)
	{
	case 1:
		do {
			FlagExist = 0;
			cout << endl << "\t请输入修改后的图书编号：";
			cin >> Num;
			cout << endl;

			for (int i = 0; i < BookRecord; i++)
			{
				if (Num == astBook[i].Num && i != BookID)//数字和已有编号重复不行，更改的编号原来一样可以
				{
					FlagExist = 1;
					cout << "\t输入错误，该图书编号已经存在，请重新输入" << endl;
					break;
				}
			}
		} while (FlagExist == 1);

		astBook[BookID].Num = Num;
		break;
	case 2:
		cout << endl << "\t请输入修改后的图书名称：";
		cin >> astBook[BookID].Name;
		cout << endl;
		break;
	case 3:
		cout << endl << "\t请输入修改后的图书作者：";
		cin >> astBook[BookID].Auther;
		cout << endl;
		break;
	case 4:
		cout << endl << "\t请输入修改后的图书出版社：";
		cin >> astBook[BookID].Press;
		cout << endl;
		break;
	case 5:
		cout << endl << "\t请输入修改后的图书库存量：";
		cin >> astBook[BookID].Amount;
		cout << endl;
		break;
	}
	//保存到文件中
	SaveBookFile(BookID);
	cout << "\t图书信息修改成功";

}
